package predict.app.music_service;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private Button start, stop;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        start = (Button)findViewById(R.id.button);
        start.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent mIntent = new Intent();
                mIntent.setAction("com.studio.android.START_AUDIO_SERVICE");//你定义的service的action
                mIntent.setPackage(getPackageName());//这里你需要设置你应用的包名
                startService(mIntent);  //启动service
            }
        });
        stop = (Button)findViewById(R.id.button2);
        stop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent mIntent = new Intent();
                mIntent.setAction("com.studio.android.START_AUDIO_SERVICE");
                mIntent.setPackage(getPackageName());//这里你需要设置你应用的包名
                stopService(mIntent);  //暂停service
                finish();
            }
        });
    }
}











